package com.chenxi.controller;

import com.chenxi.VO.MenuVO;
import com.chenxi.common.controller.BaseController;
import com.chenxi.service.MenuServiceI;
import com.chenxi.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menuApi/")
public class MenuController extends BaseController {

    @Autowired
    private MenuServiceI menuService;
    @RequestMapping("list")
    public List<MenuVO> list(){
        OAuth2AuthenticationDetails details =  (OAuth2AuthenticationDetails)SecurityContextHolder.getContext().getAuthentication().getDetails();
        System.out.println(details.getTokenValue());
        SecurityContextHolder.getContext().getAuthentication().getCredentials();
        Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        //System.out.println(userDetails.getUsername());
        ResultJson r = super.getSuccess();
        r.setData(r);
        return menuService.find(null);
    }

    public ResultJson save(){
        ResultJson r = super.getSuccess();
        return r;
    }
}
